
import ecfsConfig from '../../../config/ecfs.config.js'
import locale from '../../../config/locale/zh-CN/netCase/caseList.js'
import { basicData } from '../../../js/netCase/caseList/caseListData.js'
import * as caseListBusiness from '../../../js/netCase/caseList/caseListBusiness.js'
import * as caseListApi from '../../../api/caseList.js'
import * as userApi from '../../../api/user.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    caseStatusStyle: basicData.caseStatusStyle,
    caseInfo: {},
    locale,
   },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    wx.getStorage({
      key: 'caseInfo',
      success: function (res) {
        that.setData({
          caseInfo: res.data
        })
        if(res.data.evidence.length > 0) {
          let evidence = res.data.evidence[0]
          let { evidenceName, evidenceExplain, partyName} = evidence
          if(evidenceName.length > 10) {
            evidenceName = evidenceName.substring(0,10) + '...'
          }
          if (evidenceExplain.length > 10) {
            evidenceExplain = evidenceExplain.substring(0, 10) + '...'
          }
          if (partyName.length > 10) {
            partyName = partyName.substring(0, 10) + '...'
          }
          const _evidence = {
            evidenceName,
            evidenceExplain,
            partyName,
          }
          let evidenceList = []
          evidenceList.push(_evidence)
          that.setData({
            evidenceList,
          })
        }
      },
    })


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    const config = {
      url: (ecfsConfig.SERVER_DOMAIN + ecfsConfig.GET_USERINFO_URL)
    }
    userApi.getUserInfo(config).then(res => {
      console.log(res)
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  /**
   * 跳转到证据列表
   */
  skipToEvidence(e) {
    const pageIsFrom = e.target.dataset.type
    wx.navigateTo({
      url: '/pages/netCase/evidenceList/evidenceList?pageIsFrom=' + pageIsFrom,
    })
  },
  skipToRegisterCasePage(e) {
    let that = this 
    let isHasAccuser = false
    let isHasAppellee = false
    let isHasRequest = false
    let isHasFact = false
    if(this.data.caseInfo.accusers.length > 0) isHasAccuser = true
    if(this.data.caseInfo.appellees.length > 0) isHasAppellee = true
    if (this.data.caseInfo.requestFact.request.length > 0) isHasRequest = true
    if (this.data.caseInfo.requestFact.fact.length > 0) isHasFact = true
    const operateCaseStateList = {
      isAdd: false,
      isHasAccuser,
      isHasAppellee,
      isHasRequest,
      isHasFact,
    }
    wx.setStorage({
      key: 'operateCaseStateList',
      data: operateCaseStateList,
    })
    wx.setStorage({
      key: 'caseId',
      data: that.data.caseInfo.case.id,
    })
    wx.navigateTo({
      url: '/pages/netCase/registerCase/registerCase?isAdd=false',
    })
  },
  /**
   * 跳转到当事人或者代理人详情页
   */
  skipToPersonInfo(e) {
    let person = e.target.dataset.person
    let partyOrAgent = 1
    let partyType = 1
    let litigationStatus = 1
    let litigationStatusName = ''
    if (person.litigationStatus) {
      litigationStatus = person.litigationStatus
      litigationStatusName = person.litigationStatusName
      partyType = person.partyType
    } else {
      partyOrAgent = 2
    }
    wx.setStorage({
      key: 'person',
      data: person,
    })
    
    wx.navigateTo({
      url: '/pages/netCase/personInfo/personInfo?partyOrAgent=' + partyOrAgent + '&partyType=' + partyType + '&litigationStatus=' + litigationStatus + '&litigationStatusName=' + litigationStatusName,
    })
  }
})